package upload

import (
	"errors"
	"higame/config"
	"higame/modules/log"
	"higame/modules/utils"
	"os"
	"path"
)

type SavePath struct {
	Image string
	Html  string
}

var ImageExt = []string{
	".png",
	".jpg",
	".jpeg",
}
var FileExt = []string{
	".html",
}

func mkDirForUpload() (filePath *SavePath, err error) {
	imagePath := path.Join(utils.RootPath(), "./assets/static", config.Set.UploadImagePath)
	htmlPath := path.Join(utils.RootPath(), "./assets/static", config.Set.UploadHtmlPath)
	err1 := os.MkdirAll(imagePath, os.ModePerm)
	err2 := os.MkdirAll(htmlPath, os.ModePerm)
	if err1 != nil && err2 != nil {
		log.Error.Println("无法创建文件夹", err1.Error(), err2.Error())
		return nil, errors.New("服务器内部错误！")
	}
	return &SavePath{
		Image: imagePath,
		Html:  htmlPath,
	}, nil
}
